import axios from 'axios';

// QQ音乐API代理配置（需要自行配置代理服务）
const API_URL = '/api/qqmusic';

// 搜索音乐
export const searchMusic = async (keyword, page = 1, pageSize = 20) => {
  try {
    const response = await axios.get(`${API_URL}/search`, {
      params: {
        key: keyword,
        pageNo: page,
        pageSize: pageSize
      }
    });
    
    return response.data;
  } catch (error) {
    console.error('搜索音乐失败:', error);
    throw error;
  }
};

// 获取歌曲详情和播放链接
export const getSongUrl = async (songId) => {
  try {
    const response = await axios.get(`${API_URL}/song/url`, {
      params: {
        id: songId
      }
    });
    
    return response.data;
  } catch (error) {
    console.error('获取歌曲播放链接失败:', error);
    throw error;
  }
};

// 获取歌曲信息
export const getSongInfo = async (songId) => {
  try {
    const response = await axios.get(`${API_URL}/song/detail`, {
      params: {
        id: songId
      }
    });
    
    return response.data;
  } catch (error) {
    console.error('获取歌曲信息失败:', error);
    throw error;
  }
}; 